<template>
  <!-- 血糖范围---就诊 ---唐莉 -->
  <el-dialog
    title="设定血糖范围"
    :visible="value"
    width="700px"
    custom-class="dialog-box"
    @close="onClose"
    @open="onOpen"
    :close-on-click-modal="false"
    :append-to-body="true"
  >
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="80px"
      @submit.native.prevent="onSubmit"
    >
      <el-row>
        <!-- <el-col :span="24">
          <el-form-item label="凌晨">
            <el-input v-model="form.value"></el-input>  ----
            <el-input v-model="form.value"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="空腹">
            <el-input v-model="form.value"></el-input>  ----
            <el-input v-model="form.value"></el-input>
          </el-form-item>
        </el-col>-->
        <el-col :span="24">
          <el-form-item label="凌晨">
            <el-input class="sugar_input" v-model="form.weeHoursMin">
              <template slot="append">mmol/L</template>
            </el-input>----
            <el-input class="sugar_input" v-model="form.weeHoursMax">
              <template slot="append">mmol/L</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="空腹">
            <el-input class="sugar_input" v-model="form.limosisMin">
              <template slot="append">mmol/L</template>
            </el-input>----
            <el-input class="sugar_input" v-model="form.limosisMax">
              <template slot="append">mmol/L</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="早餐">
            <el-input class="sugar_input" v-model="form.breakfastMin">
              <template slot="append">mmol/L</template>
            </el-input>----
            <el-input class="sugar_input" v-model="form.breakfastMax">
              <template slot="append">mmol/L</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="午餐">
            <el-input class="sugar_input" v-model="form.lunchMin">
              <template slot="append">mmol/L</template>
            </el-input>----
            <el-input class="sugar_input" v-model="form.lunchMax">
              <template slot="append">mmol/L</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="晚餐">
            <el-input class="sugar_input" v-model="form.supperMin">
              <template slot="append">mmol/L</template>
            </el-input>----
            <el-input class="sugar_input" v-model="form.supperMax">
              <template slot="append">mmol/L</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="睡前">
            <el-input class="sugar_input" v-model="form.sleepMin">
              <template slot="append">mmol/L</template>
            </el-input>----
            <el-input class="sugar_input" v-model="form.sleepMax">
              <template slot="append">mmol/L</template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-button v-show="false" :loading="btnLoading" native-type="submit">提交</el-button>
    </el-form>
    <span slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
export default {
  props: ["value", "curItem", "patientId", "surgarId", "scope"],
  data() {
    return {
      form: {
        id: "",
        patientId: "",
        weeHoursMin: "", //凌晨小
        weeHoursMax: "", //凌晨大
        limosisMin: "", //空腹小
        limosisMax: "", //空腹大
        breakfastMin: "", //早小
        breakfastMax: "", //早大
        lunchMin: "", //午小
        lunchMax: "", //午大
        supperMin: "", //晚小
        supperMax: "", //晚餐大
        sleepMin: "", //睡小
        sleepMax: "" //睡大
      },
      rules: {},
      btnLoading: false
    };
  },
  created() {
    let th = this;
    th.form.date = th.getNewDate();
  },
  methods: {
    onClose() {
      let th = this;
      th.$refs["form"].resetFields();
      th.$emit("input", false);
    },
    onOpen() {
      const th = this;
      th.$nextTick(function() {
        if (th.scope) {
          th.form = Object.assign(th.form, th.scope);
        }
      });
    },
    onSubmit() {
      let th = this;
      th.form.signsType = th.caseType;
      if (th.surgarId) {
        th.form.id = th.surgarId;
      }
      let j = {};
      th.btnLoading = true;
      th.form.patientId = th.patientId;
      Object.assign(j, th.form);
      th.$api
        .savePatientGlucosePrice(j)
        .then(res => {
          if (res.executed) {
            th.$message.success("保存成功");
            th.$emit("success");
            th.onClose();
            th.btnLoading = false;
          } else {
            th.$message.error(res.message);
            th.onClose();
            th.btnLoading = false;
          }
        })
        .catch(error => {
          th.btnLoading = false;
        });
    }
  }
};
</script>
<style lang="scss" scoped>
.btn_sign_option {
  padding: 10px;
}
.sugar_input {
  width: 40%;
}
</style>